<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1">
	<meta name="description" content="A fully featured admin theme which can be used to build CRM, CMS, etc.">
	<meta name="author" content="Coderthemes">
	
	<!-- jQuery  -->
    <script type="text/javascript" src="/static/plugins/jquery/jquery-3.6.0.min.js"></script>
	
	<!-- layui  -->
	<link rel="stylesheet" href="/static/plugins/layui/2.7.6/css/layui.css" media="all" />
	<script src="/static/plugins/layui/2.7.6/layui.js" charset="utf-8"></script>
	
	<!-- 基于laiui的表格 -->
	<script type="text/javascript" src="/static/plugins/layui/extends/sku/simple_table_check_repeat.js?v=2"></script>
</head>

<body style="padding-top: 20px;">
	<form class="layui-form" id="id_form" method="post" action="/api/inter/toolsCheckRepeat/checkRepeat">
		<div class="layui-form-item">
			<div class="layui-col-md5">
				<label class="layui-form-label">国家</label>
				<div class="layui-input-block">
					<select id="country" name="country" lay-verify="">
					</select>
				</div>
				<script>
				layui.use('form', function(){
					var form = layui.form;
					$.ajax({
						type: "POST",
						url: '/api/inter/ysDict/listAll',
						data: {},
						success: function (data) {
							
							if (data.code == 0) {
								var h = '<option value="">请选择国家</option>';
								var options = data.data['TB_RepeatWord-Country'];
								for(var i = 0; i < options.length; i++) {
									var option = options[i];
									h += '<option value="' + option.value + '">' + option.name + '</option>';
								}
								$('#country').html(h);
								form.render();
							} else {
								alert(data.msg);
							}
						}
					});
				});
				
				</script>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-col-md6">
				<button type="button" class="layui-btn layui-btn-normal" style="margin-left: 50px;" id="select_mul_file">选择多文件</button>
				<button type="button" class="layui-btn layui-btn-danger" onclick="location.reload();" style="margin-left: 30px;"><i class="layui-icon layui-icon-refresh"></i>重置</button>
				<button type="button" class="layui-btn" style="margin-left: 30px;" lay-submit lay-filter="formSubmit"><i class="layui-icon layui-icon-search"></i>查询</button>
				<div class="layui-input-block">
					<script>
					var indexOfLoading; // 加载中弹窗序号
					var rowsOfReaded = [];
					layui.use(['upload'], function(){
						
						layui.upload.render({
							elem: '#select_mul_file',
							accept: 'file',
							acceptMime: 'application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
							ext: 'xlsx|xls',
							url: '/api/inter/toolsCheckRepeat/readExcel',
							auto: true,
							multiple: true,
							number: 10,
							choose: function(obj){
								indexOfLoading = layer.load(1, {
									shade: [0.5,'#000000'] //0.1透明度的白色背景
								});
								//将每次选择的文件追加到文件队列
								var files = obj.pushFile();
								
								//预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
								obj.preview(function(index, file, result){
									
									//obj.resetFile(index, file, '123.jpg'); //重命名文件名，layui 2.3.0 开始新增
									
									//这里还可以做一些 append 文件列表 DOM 的操作
									
									//obj.upload(index, file); //对上传失败的单个文件重新上传，一般在某个事件中使用
								});
							},
							progress: function(n, elem, e, index){
								//dom.val(n + '%');
							},
							done: function(res){
								console.log('-------done------', res);
								var rows = res.data;
								for(var i = 0; i < rows.length; i++) {
									rowsOfReaded.push(rows[i]);
								}
								return;
							},
							allDone: function(obj){ //多文件上传完毕后的状态回调
								layer.close(indexOfLoading);
								console.log('-------allDone------', rowsOfReaded);
							}
						});
					});
					</script>
				</div>
			</div>
		</div>
	
		<!-- 查重结果 -->
		<div class="layui-form-item">
			<div id="simple_table_check_repeat">
			</div>
			<script th:inline="javascript">
			var tableOfSysDict = null;
			//使用layui的sku模块
			layui.use(['form', 'simple_table_check_repeat', 'jquery'], function(){
				var $ = layui.jquery,simple_table_check_repeat = layui.simple_table_check_repeat,form = layui.form;
            	
				tableOfSysDict = simple_table_check_repeat.init({ id:'simple_table_check_repeat', data: []});
			});
			</script>
		</div>
	</form>
	<script>
	$(function () {
		layui.use(['form'], function(){
			var form = layui.form;
			
			// 表单提交，共用同一个
			form.on('submit(formSubmit)', function(data){
				var indexOfLoading = layer.load(1, {
					shade: [0.5,'#000000'] //0.1透明度的白色背景
				});
				data.field['detailArr'] = JSON.stringify(rowsOfReaded);
				$.post(data.form.action, data.field, function(res){
					if (res.code == 0) {
						if(res.data.rows.length == 0) {
							tableOfSysDict.reloadRowsNoData();
						} else {
							tableOfSysDict.reloadRows(res.data.rows);
						}
					}
					layer.close(indexOfLoading);
					layer.msg(res.msg);
				});
				return false;
			});
		});
	});
	</script>
</body>
</html>